Handling Deferred objects in JavaScript functions results (not quite working yet).