better way to do queries, courtesy of erwin