refactoring / added retry mechanism