Track sorting and listing improvements. (Bug 796305 and bug 841977)

Includes dependencies that have to land before this. ie will be rebased when time comes.
Note that it's possible (but unlikely) that this won't get you the maximum `disccount` value, since you're sorting by `discnum` and not `disccount`.