add more test cases and fix all bugs