got code to sort in two dimensions + keep track of counts