sorting also applied on 1D data, fixed some small bugs