added rudimentary flow control