core-4855 add sorting logic and fix unit test