Moved common functions to functions.lua