add tests & fix sort