Add sort/keep logic