Fix if in loop