Refactor toDigitsReg - thanks dalaing