rearrnaged the reading code to give an easier API