Updated match word function