Fix tests
Refactor DB module code