(core) refactor, moved direct lua calls out of main into lua