Fix bug in refactor