Added comments and did some minor refactoring