fix a bug and add few testcase.