Implemented word counter function.