Fixing Vertical Rotation of 3D Objects

I am writing a simple 3D Renderer using Desmos. It uses 3 lists dedicated to the x,y, and z values as well as an additional list for the indices and face creation of the cube. I implemented rotation alongside the X axis, and it works great! But when trying to rotate vertically, the picture gets extremely distorted. I assume this has to do with the order in which rotations and transformations are applied, however, I do not know how to change the order without breaking the projection? Any suggestions would be much appreciated! Thank You!

The forum here is for use of the Activity Builder, and primarily the Computation Layer. While graph component questions can be relevant, this may be out of the scope for most users. You’ll likely get better help from the help page at support.desmos.com. There are also some very knowledgeable users on the r/desmos subreddit that share and assist with complex graph questions.