fix some bugs, need more debug