Fixed bugs in DB code.