made resilient to garbage data ahead of stream and ensured the last png is saved at the end of stream