Minor refactoring, comments, removal of unused imports.