Functional refactor