updating to work with lua 5.2 and cleanup