Add two-dimensional sorting function.