Refactor to use promise