Fixed bug in DB code