more UT and fixes for sorting and removing