updated to read in a loop