fix sort
add tests