Refactored Promise to use the loop.