added sorting, updated test files and unittests