fixed wrong variable in read function