Moved some code for 3D rendering