wrote match score function