Fixed bug in closing db

The pointer to the database that was closed is now being removed