What is the best way to get a close-to-fair coin toss from identical biased coins? (Von Neumann gave an algorithm that simulates a fair coin given access to identical biased coins. The algorithm potentially requires an infinite number of coins (although in expectation, finitely many suffice). This question concerns the case when the number of coin tosses allowed is bounded.)

Suppose we have $n$ identical coins with bias $\delta=P[Head]-P[Tail]$. The aim is to simulate a single coin toss while minimizing bias. 

The simulation must be efficient in the following sense: An algorithm running in polynomial time looks at $n$ random bits and outputs a single bit. The bias of the algorithm is defined as $Bias(A)=|E[A=0]-E[A=1]|$ where the expectation is taken over the distribution defined by $n$ i.i.d bits ${x_1,\ldots,x_n}$ such that $Prob[x_i=1]-Prob[x_i=0]=\delta$.


  Which algorithm $A$ running in polynomial time has the least bias $Bias(A)$?


This question seems very natural to me and it is very likely that it has been considered before.

What is known about this problem? Is anything known when a weaker class (in $AC_0$, etc.) of algorithms is considered?
Tossing n biased coins and taking the parity of heads gets exponentially close to $\frac{1}{2}$. 

[For a proof, consider a random variable that is -1 when heads and 1 when tails, then
the probability that there are an odd number of heads is just the $E\left[\frac{1}{2} + \frac{1}{2}\prod_i X_i\right] = \frac{1}{2} + \frac{1}{2}\delta^n$]

Perhaps this is also optimal for the following reason. Let $f$ be any composition function of these bits. Then, the $\text{Bias}(f) = \sum_S \hat{f}(S) \delta^{|S|}$ and the best $f$ seems to be the parity function (isn't it?). 

If you are interested in composition functions of lower complexity, then perhaps a paper of Ryan O'Donnell on `Hardness amplification within NP' would be very relevant. There he uses monotone composition functions for hardness amplifications and the functions that work are characterized by their noise sensitivity.