Some general cleanup of the file parsing process

Some refactoring to split it into smaller functions is likely due.