Avoid polluting global namespace

Make it so that TableLock is added to the global namespace and all its
dependencies are in a function closure so as to not pollute the global
namespace.