Fix bugs causing a Reader infinite loop.