Major bug fixes in dbhandler