more commenting and refactoring