refactor some lua