Refactor 3D to use shared pointers