Remove duplicate code in DatasetLoader