use a Lua module and localize functions
fix formatting
move connect string into function
Merge pull request #168 from bakins/luaoptimizations

Lua optimizations