small loop fixes