Invalid reference in refactored conditional