Added corrected sorting and searching