Re implement locking

There's a couple other changes included that fix compilation warnings that were showing up in other modules.