Refactor out common code for running workflows.

This probably results in some bug fixes for the API workflow running - such as running tools with multiple=true data input parameters.
Refactor 2 paths of workflow step invokation into helper functions.