Part 2 of #5 solution