fix some bug and add test