add check to avoid endless loop