CONTRIB-3782 Added some more tests and updated the code to account for some new test cases.