Refactored flow control