wrote read function