Search method

I have reimplemented this based on a fresh update of the master branch from upstream. Please see if this commits more cleanly.