improvements to inline function, moved it to util.lua
removed some unnecessary code.