Reworked most of UglyNumbers implementation.