this condition has to be changed to if(!mergedPhoto) otherwise we will take as first photo the photo of the last matching contact, thus changing the logic