refactoring, clean up, and documentation