Refactoring with functions