[FIX] Write some test cases and fix some bugs.