made sorting with pinned flag