refactor to use promises instead of callbacks