def query fix

@steveoh Would you mind taking a look at this to make sure that I'm not
screwing anything up?