Fix infinite loop in certain case, thanks @Bridouille