3D optimizations, refactoring, minor changes