Fixes chained queries

@matthuhiggins