Moved references to ents inside the if-statement