added category selection and updated query logic