since we're generating functions in a loop, use closure wrapper