Tidied Up Code

Cleaned up and adjusted some code to simplify the 3D functions.