[ refactor ] moved a couple of local functions to top-level