fixed database closing