Some improvement on the db, mostly correct close to remove it after close, fix not initialised variable too