refactoring related bugs fixing