sorting now works for two dimensions