Fix for a rare infinite loop