Fixed comments and did some refactoring