This seems to find the closest stop

I am not sure why it does so any comments added after the third from the last if would be helpful going forward.  Multiple patterns may not work if stop desired in wrong pattern.