perfected file i/o