Fixes to 3D code