Convergence and optimality of hp-AFEM