Improvements

Several things may be worth changing in the workflow: use the streamID in particular. Check comments in the code.