Structure of queries changed

So please get this into the master