solves problem 8