bugfix: pass the index to failure, not the stream :\
refactor to eliminate CPS in the absence of TCO