Simplify and speed up the input selection logic.