   handleAddTerm: ->
     queryTerms = @state.queryTerms
     queryTerms.push(createTerm())
+    queryTermIds = @state.queryTermIds
+    queryTermIds.push(lastQueryTermId++)
+
+    @setState(queryTermIds: queryTermIds)
     @props.handleQueryChanged(@constructCQPQuery(queryTerms))
 
 
   handleRemoveTerm: (termIndex) ->
     queryTerms = @state.queryTerms
     queryTerms.splice(termIndex, 1)
+    queryTermIds = @state.queryTermIds
+    queryTermIds.splice(termIndex, 1)
+
+    @setState(queryTermIds: queryTermIds)
     @props.handleQueryChanged(@constructCQPQuery(queryTerms))
 
 

#= require ./cwb_multiword_term

###* @jsx React.DOM ###

createTerm = (overrides = {}) ->
  term =

          {queryTerms.map(function(term, index) {
            return (
              <CwbMultiwordTerm
                key={this.state.queryTermIds[index]}
                term={term}
                termIndex={index}
                queryHasSingleTerm={this.state.queryTerms.length === 1}
