Fixed bug in picking best match