rewritten read function