Ported to lua 5.2