fixed bug to close database