     thead = element.find "thead"
 
     if thead[0]
-
       tr = thead.find "tr"
-
       existing_ths = {}
-
       for th in tr.find "th"
         th = angular.element(th)
         existing_ths[th.attr("attribute")] = th.html()
 
       tr.remove()
+      tr = $("<tr></tr>")
 
       tds = element.find("td")
-
-      tr = $("<tr></tr>")
       for td in tds
         td = angular.element(td)
         attribute = attributeExtractor.extractAttribute(td)

    }
    link: ($scope, $element, $attributes) ->
      $scope.stub = {}

      $scope.stub.list = $scope.list

      $scope.stub.itemsPerPage = $scope.itemsPerPage

      $scope.stub.currentPage = 0

      $scope.update = () ->

    restrict: "AC"
    scope: true
    compile: (element, attributes, transclude) ->
      paginationName = attributes.pagination
      listName = attributes.list || "#{paginationName}.list"

      constructHeader(element)

      tbody = element.find "tbody"
      tr = tbody.find "tr"
      tr.attr("ng-repeat", "item in #{listName} | limitTo:fromPage() | limitTo:toPage() | orderBy:predicate:descending")
      {
        post: ($scope, $element, $attributes) ->

