File processing code refactoring