fixing DB closing and shutdown problem.