Refactoring to be more functional