refactor to use promises