middleware flow control