Debugged db.cpp