hopefully optimise some queries