implemented sorting and searching