new version with some flow control