Completes up to problem 5