re-factor as function workflow