Fix infinite loop