db tests and rewrite to make it work