Don't zero out numwritten before using.... Found by Pierre Belanger belanger@pobox.com