Fix bugs in DB