adding inline documentation & refactoring