code clean up and new functions to 3d plotting function