fixed an infinite loop