Instead of requerying, the query on line 249 can be changed to select the categoryid.