Refactored duplicate code from FileLoader