db tests and some improvements