Improved numbers algorithm