Updated solution for 5th exercise to more elegant solution.