Fix control flow of promises