Simplify code with Chapter 5 exercises