Cleaned up code and commented it