Replaced get digit with a better implementation