additional code commenting and refactoring