refactoring to handle large files