fixed some bugs caused by the refactor