refactored to use promises