added test cases and fix bug