fix a bug and more tests