simplify query code