comments and refactoring; bug detected