refactor more code into lua.js