Refactor to use promises