Added code for more robust data file opening and other misc changes.