Cleaned up code and commented.