add missing lock/unlock (not finished, not tested)