toDigit method fixed (infinity loop deleted)