Refactoring : using promises