Refactoring to more functional