Fixing issue #52
Fixing issue #49
Adapting to Lua 5.2