Fix infinite loop issue