added 3D visualization and refactored some code