Cleanup of the dataset retrieval function