Cleaning up #168 + added new test cases.