refactored code for repeat widget and subsequent ones to follow