Split out file reading code.