refactoring bugs fixed