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