add more tests and improve a few queries