created refresh function for repeated code