fixed bug in stream model where forEach was used instead of map.  

Also added some optimisations