Tried factoring out query types etc