Simplification of exercise 2 - use of function composition