         #sort by weight, then return list of names
         cmp_weight = (a,b) -> a.weight - b.weight
         res = sug_list.sort( cmp_weight ).map( (a) -> a.name )
-        #console.log(res)
         Session.set("suggestions_#{ @_id }", res)
         
         event.stopImmediatePropagation()
         
     "click button[name='enter_tag']": (event) ->
       if not event.isImmediatePropagationStopped()
-        tag_text = event.target.parentNode.getElementsByTagName(
-          "textarea")[0].value
-        if tag_text != "" # && not @my_tags[tag_text]?
-          #add to @my_tags not @tags
+        tag_box = event.target.parentNode.getElementsByTagName(
+          "textarea")[0]
+        tag_text = tag_box.value
+        #TODO: Encapsulate this code
+        if tag_text != "" #TODO: && not @my_tags[tag_text]?
+          #TODO: add to @my_tags not @tags
           @tags[tag_text] ?= { users: [], weight: 0}
-          @tags[tag_text].users.push(Meteor.call("get_user_id"))
+          @tags[tag_text].users.push(Session.get('user_id'))
           Posts.update(@_id, {$set: {tags: @tags}})
+          #clear textbox and update suggestion filter
+          tag_box.value = ''
+          Session.set("filter_text_#{ @_id }", '')
+          Session.get("context_#{@_id}").invalidate()
         event.stopImmediatePropagation()
         
     "click button[name='done_tagging']": (event) ->

    ret += " suggested' tabindex='0'>" + tag + "</form>"
  return ret
)

$(document).keydown( (event) ->
  console.log(document.activeElement)
  event.stopPropagation()
)

# -@tags -> @graduated_tags
# -info -> weight
# -info.weight -> weight
# -'TODO's indicate case-specific changes
###
_.extend( Template.tagbox,
  add_tag: (tags, tag_text, event, id) =>
    console.log(tags, tag_text, event, id)
    if tag_text != "" #TODO: && not @my_tags[tag_text]?
      #TODO: add to @my_tags not @tags
      tags[tag_text] ?= { users: [], weight: 0}
      tags[tag_text].users.push(Session.get('user_id'))
      Posts.update(id, {$set: {tags: tags}})
      #clear textbox and update suggestion filter
      event.target.value = ''
      Session.set("filter_text_#{ id }", '')
      Session.get("context_#{ id }").invalidate()
    
  visible_tags: ->
    visible = (tag for tag of @tags)  #graduated tags
    @my_tags ?= {}                    #TODO: REMOVE on schema change
    for name of @my_tags              #my tags
      if not (name in visible)
        visible.push(name)
    return visible
    
  suggested_tags: -> 
    suggestions = Session.get("suggestions_#{ @_id }")
    filtered = []
    for tag in suggestions
      filtered.push(tag) if tag? &&
        tag.search(Session.get("filter_text_#{ @_id }")) != -1
    return filtered

  tagging_post: -> Session.equals("tagging_#{ @_id }", true)
  
  events: {
    ###
    'focus .suggested': (event) ->
      if not event.isImmediatePropagationStopped()
        #console.log(event.target,"clicked")
        #event.target.focus()

        event.stopImmediatePropagation()
    ###
    ###
    'keydown .suggested': (event) ->
      if not event.isImmediatePropagationStopped()
        tag_text = event.target.innerText
