switched to use a do-while loop, which reads much more nicely.