reworked to use promises