refactored Lua code

Hi, I refactored the Lua code slightly.