Move db code into db.go