Completed part 4, still to run it against more test cases