add testcase and fix bugs.