Some trivial re-formatting changes.
Change several of the top-level functions to use the locking class instead of the old method for locking.
Fix some issues with merging.