Refactor control flow WIP