Problem 6, and cleaned up problem 3