Refactor create-or-update-average to enforce DRY principle