Make the sort cleaner with anonymous functions.
Make merging consistent with watershed method using lowest gradient.