Add sort to code