Refactor selection logic