[wip] move flow control functions to a separate script