     $('.entity').on eventType, (event, ui) ->
       drawRelationshipsFromEntity(event.currentTarget)
 
+entityBox = (entity_id) ->
+  e = $('#entity' + entity_id).parent()
+
 entityCoordinates = (entity_id, xloc, yloc) ->
-  e = $('#entity' + entity_id).parent()
+  e = entityBox(entity_id)
   x = Math.round(e.offset().left + e.width() * xloc)
   y = Math.round(e.offset().top  + e.height() * yloc)
   return {x:x, y:y}
 
 entityCoordinate = (entity_id, side) ->
-  e = $('#entity' + entity_id).parent()
+  e = entityBox(entity_id)
   switch side
     when "left"   then coord = e.offset().left
     when "right"  then coord = e.offset().left + e.width()

        p2.y = entityCoordinate(entity2, "bottom") - MARGIN

  return [p1,p2]

closer_to_vertical_than_horizontal = (entity1, entity2) ->
  entity_positions = [[0,0],[0,1],[1,1],[1,0]]

    p2.x = entityCoordinate(entity2, p2.side)

    if fully_horizontal(entity1, entity2)
      p1.y = horizontal_relationship_y_coordinate(entity1, entity2)
      p2.y = p1.y
    else
      if center1.y < center2.y
