Some commenting and refactoring