more functional refactoring