Finally made the read() more robust.