fix wait loop in read proc; added return values