Got selection of pattern to work.
Move common pattern selection functionality to a subroutine.