added error handling for bad file format