Threadsafe database

A bit of a big hammer, there...

I've made distinct commits, for ease of review, but I figure they all kind of go together. If you review the commits, remember that notifications for comments made on commits can "go in the wrong place", so please make the comments on the pull request, thanks!
I realise now that these methods are named backward. They should be called ```NoLock```, not ```Unlocked```.

Please imagine that they are called differently, I will fix that before merging. :smiley: