Redo locking

Plus misc other stuff that crawled in