Fix bug from refactoring code