refactoring bug fix