fixed bug that resulted in an infinite loop