Simplify query function

Making more transparent what I'm actually doing.