Fix remaining bug and update test cases