Eliminating terrible code and duplicate numbers