Optimise slow queries

Following Sean Pringle's recommendations

Change-Id: I430574818d7fe1abb0206d33635840387f547ebe