cleaned up the code in problems 8 and 9
Cleaned up problems 8 and 9 to make code more readable