removed locks around all the individual accesses to sqlite connection and use a lock only in the scope.