Add a destructor and use it to close the database