Refactoring to Functional Style