some loop fixes