improve query for getting categories names and ids