refactor database setup