Fix for infinite loop