removed inline function and sub with lua code - slow but works