refactor repeated code