Fix for open lock on db files. Need to fully test before merging to master, keeps file open now until finished all transactions.