new port
lua5.1 fix
splitted into separate files