Refactor code.

Reuse code that iterates over $PATH.