First 3 problems refactored. Problem 4 nearly ready.