redid read() with while loop, needs testing