Fix infinite loops