fixed bug and testcases