Cleaned up code and added docs to all functions/variables