Refactor/implement promises