More commenting and refactoring