Move nsql publishing to its own thread.

Publishing was hanging the main lua update thread.
local-ize some variables.
Merge pull request #67 from captdeaf/master

Move nsql publishing to its own thread.