refactor process_selections
and fix bugs exposed by tests