Improved plot3d function