Simplify sorting logic

Python's sorting is stable, so we can just sort multiple times (starting
on the least-significant field) rather than building a tuple of
(possible negated) sort keys and sorting on the tuple.