added error checking on file open