changes to outputting of files

- also fixed small bug in i/o code