minor refactoring and editing