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.

I don't know why GitHub is reporting like a changed the whole file; maybe my editor changed the whitespace a bit.  I just slightly changed TableLock so that only the TableLock function is global.  Everything else is in a closure.