Refactor lua interface