Moved file processing into its own function, general cleanup.