Modification to main match algorithum.