Fix support for Lua 5.2 and various small issues