Added failsafe for neverending iterations