 
     after = (->) if after is null
 
-    @getInstance table, (db, collection) =>
+    @getInstance table, (collection) =>
       collection.count params, (error, results) =>
         if error
           console.log 'Error with fetching counts: ' + error

        console.log 'Error with connection to MongoDB server: ' + error if error

        @db = db
        @getCollection table, db, after

  getCollection: (table, db, after) ->
    if @collection.object isnt null and @collection.name is table
      after @db, @collection.object
    else
      db.collection table, (error, collection) =>
        console.log 'Error with fetching collection: ' + error if error

        @collection = name: table, object: collection
        after @db, @collection.object

  findById: (table, id, after = ->) ->
    @getInstance table, (db, collection) =>
      try
        params = _id: ensureObjectId id
      catch exception

        after parseInt results, 10

  save: (table, params, after = ->) ->
    @getInstance table, (collection) =>
      try
        params._id = ensureObjectId params._id if params._id?
      catch exception
