functional refactor