Added db.cpp and fixed some errors