fixing a few infinite loop bugs, ugh!