adding query and sort