Use $.when for chained promises

Use $.when instead of nested scopes, when the results of two promises are needed.