Add new test cases and fix remaining bugs