refactoring: less nesting