refactor .done .fail to .then