Making go program predictable.

Some small things I noticed. sort.Sort() is not stable which means that the order is not deterministic. sort.Stable() is stable.

And some duplicated code.