cleaning up the queryby code