Refactor to slightly improve performance on large files.