refactoring with function composition