refactor lua port