Fixed refactoring bugs