cleaned up the code a bit and added a new test case