refactoring bug fixed