Remove global lock
This is based on the code from merge requests !12 (closed) and !13 (closed), but I made it hopefully correct so that we can merge it.
This is based on the code from merge requests !12 (closed) and !13 (closed), but I made it hopefully correct so that we can merge it.