added json output for matches.
more fixing and tidying up.