Fixing database close error