Introduce StreamIndex to clean up code