Refactoring with named function