Revert "Revert "Fix CA selection logic""

This reverts commit 6d2a90afdd82bf1fe066e7d4d6e9fe7a9bbffcf4.