Clean up code in db.c