Added error checking and handling for data files