slight refactoring and documentation