Better handle reopening of databases