Fix serializing generator expression
Generalize get_opts_fields to work with any collection