Fixed problems with calling read() multiple times