fix refactoring bugs