fixed refactoring bugs