Fix ended stream problem