replaced nested callbacks with promises