Fixed race condition in flow control

Fixes #28