lua code should now be more efficient