fixed looping bounds error