comments and minor refactoring