Solved problem 4, cleaned up problem 3