Send error only once and consider stream closed
Re-indent code block
Cleanup stream position update block