WIP converting keysFor logic to Lua