Logic was wrong

Imported change from an old version