added a check in closestwordsmethod