problem 8 with some extra comments