Adding the test cases and the new implementation.