updated match word function