Fix loops handling