add test cases and fix