Possibly fixed infinite loop bug