refactor word counting to hash#reduce