Factor out rewriter
Clean up, add @workflowContext implementation