Prevent division by zero if all two-dimensionally sorted items have same value, and improve trace for sort