fix closing and opening a new database