fixed shitty logic that allowed infinite loops to occur