Fix some bugs due to refactoring