Fix loops processing (from skylot)