refactoring ajax calls with promises