refactored tests and databse handling