simplified reordering. added unit tests for reverse sorting