   countPages: _.throttle ->
       @call "CountPages", ((e, r) ->
         @sess "totalPages", r
+        if @sess("currentPage") > r
+          @sess "currentPage", 1
       ).bind(@)
     , 100
   publishNone: ->
-    @realFilters = false
     @ready()
     return @Collection.find null
-  publish: (page, subscription) ->
+  publish: (page, sub) ->
     check page, Number
-    check subscription, Match.Where (s) ->
+    check sub, Match.Where (s) ->
       s.ready?
-    connectionId = subscription.connection.id
+    cid = sub.connection.id
+    get = sub.get = ((cid, k) -> @get k, cid).bind(@, cid)
+    set = sub.set = ((cid, k, v) -> @set k, v, cid: cid).bind(@, cid)
+    delete @userSettings[cid]?.realFilters
+    delete @userSettings[cid]?.nPublishedPages
     @setPerPage()
-    skip = (page - 1) * @perPage
+    skip = (page - 1) * get "perPage"
     skip = 0  if skip < 0
-    filters = @filters
+    filters = get "filters"
     options = 
-      sort: @sort
-      fields: @fields
+      sort: get "sort"
+      fields: get "fields"
       skip: skip
-      limit: @perPage
-    @realFilters = null
-    @nPublishedPages = null
+      limit: get "perPage"
     if @auth?
-      r = @auth.call @, skip, subscription
+      r = @auth.call @, skip, sub
       if !r
         return @publishNone()
       else if _.isNumber r
-        @nPublishedPages = r
+        set "nPublishedPages", r
         return @publishNone()  if page > r
       else if _.isArray(r) and r.length is 2
         if _.isFunction r[0].fetch

  subscriptions: []
  userSettings: {}
  methods:
    "CountPages": ->
      return @nPublishedPages  if @nPublishedPages
      n = Math.ceil @Collection.find(@realFilters).count() / @perPage
      n or 1
    "Set": (k, v, subscription) ->
      check k, String
      check v, Match.Any
      check subscription, Match.Where (s) ->
        s.connection?.id?
      if v?
        changes = @_set k, v, cid: subscription.connection.id
      else
        changes = 0
        for _k, _v of k
          changes += @set _k, _v, cid: subscription.connection.id
      changes
    "Unsubscribe": ->
      subs = []

          delete doc._id
          unless init
            #Add to @PaginatedCollection
            sub.added(@id, id, doc)
            (@Collection.find get "filters",
              sort: get "sort"
              fields: get "fields"
              skip: skip
              limit: get "perPage"
            ).forEach (o, i) =>
              if i >= at
                sub.changed(@id, o._id, _.object([["_#{@id}_i", i + 1]]))
        catch e
      ).bind @, sub
    handle2 = c.observeChanges
      movedBefore: ((sub, id, before) ->
        ref = false
        (@Collection.find get "filters",
          sort: get "sort"
          fields: get "fields"
          skip: skip
          limit: get "perPage"
        ).forEach (o, i) =>
          if !ref and o._id is before
            ref = true
            at = i
          if ref
            sub.changed(@id, o._id, _.object([["_#{@id}_i", i + 1]]))
          sub.changed(@id, id, _.object([["_#{@id}_i", i]]))
        #Change in @PaginatedCollection
      ).bind @, sub
      changed: ((sub, id, fields) ->
        try
          #Change in @PaginatedCollection
          sub.changed @id, id, fields
        catch e
      ).bind @, sub
      removed: ((sub, id) ->
        try
          #Remove from @PaginatedCollection
          sub.removed @id, id
        catch e
      ).bind @, sub
    n = 0
    c.forEach ((doc, index, cursor) ->
      n++
      doc["_#{@id}_p"] = page
      doc["_#{@id}_i"] = index
      #Initial add to @PaginatedCollection
      sub.added @id, doc._id, doc
    ).bind @
    init = false
    sub.onStop ->
      handle.stop()
      handle2.stop()
    @ready()
    @subscriptions.push sub
    c
  loading: (p) ->
    if !@fastRender and p is @currentPage() and Session?
