Refactored code to prepare for workflow restore