Cleaned up code and made some more comments