fix bug with read loop