Finally fixed the text stream's read function