Few optimizations: avoid strlen when string length is known (read()>0 return);