fixed exception during closing of fully read stream

This is fix for #159. It includes #158, I'm not quite sure how to better deal with dependent PRs.