Added a check on whether the data file was successfully opened