refactored deferred.js