fix some bugs after refactoring