Added nan and inf check to iterate method