create ave bg function