Fixed bug that caused an infinite while loop.