commented code, minor refactoring