Use $.when for promise handling

Change-Id: If56e331167a3e51582c10e08083355a9f76f16ad
Merge "Use $.when for promise handling"