 class DeleteAnnotationCommand
   constructor: (@annotation) ->
     @annotation.submissionPage.annotations.remove(@annotation)
-    @annotation.phrase.criterion.annotations.remove(@annotation)
+    @annotation.phrase.criterion.annotations.remove(@annotation) if @annotation.phrase?
     @annotation.deleted = true
   
   undo: ->

  
    # Subscribe to screen position changes to update pagePos after dragging.
    @screenPosition.subscribe =>
      console.log "screen position observer triggered"
      screenPos = @screenPosition()
      pagePos = @pagePosition()
      pagePos.x = screenPos.x / @zoom

    @annotationEditor.subscribeToAnnotation(command.annotation)
    

  deleteAnnotation: (annotation, event) =>
    @annotationEditor.addCommand(new DeleteAnnotationCommand(annotation))
    event.preventDefault()
  
    
class Annotation
