added test cases, cleaned up code, fixed part 3