Some more refactoring to allow better handling of multiple input files.