performance improvements for lua script