Refactor to make code reuse easier for testing.

Add first test & fix bug where title substring match would not
be attempted.