Fixed crashes in DB, because the DB got closed prematurely