Fix test cases and bugs.