io error catching and piece valid optimization