Swapped condition checks to attempt to reduce used cycles.