Added comments, cleaned up parts of code