Refactorings to use promises