refactor word logic