Refactor locations of shared Lua code