refactored 'repeat action' code