Add sort button and refactor