Fixed bug that causes infinite looping.