the file I/O is just about working; for some reason it fails for large files