fix some bug and refactor a little