fixed some looping issues