implemented word counting mechanism