fix bug handling slow readers
add tests to cover more cases, and split into 2 files