refactor selection-tool to extract common conditions