this whole bit was encapsulated in the `filter_to_upload` function to make this section easier to read. I think we should do that again with the logic below.