Refactor the proxy selection into a separate algorithm