Added test cases. Seems to work, but more test cases would probably be beneficial.