Refactored to use promises