Refactoring towards promises