Use when.js for handling promises