More or less final version of the code for digits.