Fixed and improved 3D rotation code.