commented code, slight refactoring