Fixed logical error in refactor