refactored with promises