fixed the db close issue