Added check for the end of stream reached fixed #49