Fix infinite recursive function