update stack_btw_replica function