Refactoring and fix retry of rejected promise