shifting mroe code to lua script