correcting an infinite loop