Improve modularity of selection.py