Attempting to solve problem 3