Small fixes and more tests for closing a writable stream

Only affects reference implementation.