refactor to use promise