       itemsById[newItem[idField]] = newItem
       return
 
-    all = (params, callback) ->
+    all = (params) ->
+      deferred = $q.defer()
       options = {}
       cacheable = true
       r = resource
 
-      if _.isFunction(params)
-        callback = params
-        if items.length > 0
-          callback items if callback
-          return
+      if not params? and items.length > 0
+        deferred.resolve items
       else
-        cacheable = false
+        if params?
+          cacheable = false
+
         options = params
 
-        if params.query?
+        if params?.query?
           r = queryResource
 
-      r.query options, (results) ->
-        if cacheable
-          items = results
-          angular.forEach results, (item, index) ->
-            itemsById[item[idField]] = item
-            return
+        r.query options, (results) ->
+          if cacheable
+            items = results
+            angular.forEach results, (item, index) ->
+              itemsById[item[idField]] = item
 
-        callback results if callback
-
-    allPromise = (params) ->
-      deferred = $q.defer()
-
-      if params
-        all params, (results) ->
-          deferred.resolve results
-      else
-        all (results) ->
           deferred.resolve results
 
       deferred.promise
 
-    save = (item, success, fail) ->
+    save = (item) ->
+      deferred = $q.defer()
+
       if item[idField]
         #we are updating
         resource.save {id: item[idField]}, item, (result) ->
           updateMasterList result
-          success(result) if success
+          deferred.resolve result
         , (failure) ->
-          fail(failure) if fail
-
+          deferred.reject failure
       else
         #we are createing a new object on the server
         resource.create {}, item, (result) ->
           updateMasterList result
-          success(result) if success
+          deferred.resolve result
         , (failure) ->
-          fail(failure) if fail
-
-    savePromise = (item) ->
-      deferred = $q.defer()
-      save item, (res) ->
-        deferred.resolve res
-      , (err) ->
-        deferred.reject err
+          deferred.reject failure
 
       deferred.promise
+
 
     getCached = (id) ->
       return itemsById[id]

      version: version
      clearCache: clearCache

    if usePromises
      exports.all = allPromise
      exports.query = allPromise
      exports.get = getPromise
      exports.save = savePromise
      exports.destroy = destroyPromise

    exports

  #export the crud factory method

, ['$resource', '$q', 'giSocket'
, ($resource, $q, Socket) ->

  factory = (resourceName, prefix, idField) ->

    if not prefix?
      prefix = '/api'
