Fix database close