Without use of the Axiom of Substitution, using Transfinite Recursion to prove the Counting Theorem I'll inevitably need to provide some background information to present this question, so here it goes; I state all of the requisite information below.
I've been teaching myself some Set Theory by working through the Dover version of Smullyan and Fitting's Set Theory and the Continuum Hypothesis, and I've come to this problem which has troubled me:

Exercise 5.1 (of Chapter 6).  Prove that if we delete the axiom of substitution and add Theorem 5.8 as an axiom, we can then prove the counting theorem. 

Theorem 5.8 is one form of transfinite recursion. "$\mathrm{On}$" is the class of all ordinals, and for any set $x$, "$F^{\prime\prime}(x)$" denotes the class of all sets $F(y)$, where $y$ belongs to $x$.

Theorem 5.8 (of Chapter 6).  For any function $h$ there is a unique function $F$ on $\mathrm{On}$ such that for every ordinal $\alpha$, $F(\alpha) = h(F^{\prime\prime}(\alpha))$.

(Note that this presupposes that $F^{\prime\prime}(\alpha)$ is a set, for each ordinal $\alpha$.) 
A properly well ordered class is a well ordered class in which every proper lower section is a set. 

Counting Theorem (Theorem 4.1 of Chapter 6).  Every properly well ordered class $A$ is isomorphic to either an ordinal or $\mathrm{On}$ itself.  Moreover, if $A$ is a set, $A$ is isomorphic to an ordinal, whereas if $A$ is a proper class, $A$ is isomorphic to $\mathrm{On}$.

My attempts:  I've been able to show that if $A$ is a (properly) well ordered set, then $A$ is isomorphic to an ordinal.  However, I encounter difficulty when assuming that $A$ is a proper class--every time I seem to be getting close, I run into a situation where I seem to require the axiom of substitution, at which point all is lost.
What's been most successful for me is to define $h$ by
$$h(x) = \begin{cases}
\min (A - x),  &\text{if }A-x\text{ is not }0, \\
A,  &\text{if }A-x = 0.
\end{cases}$$
(Note: if $A-x = 0$, $A$ is a subclass of the set $x$, so that $A$ is then a set; then $h$ is well defined.)
We then use this $h$ to define $F$ per Th. 5.8. 
I've been able to show that:
$$F(a) = A\text{ for some }a \iff A\text{ is a set.}$$
Then, taking $m$ to be the least ordinal such that $F(m) = A$, I've been able to show that $F\restriction m$, the restriction of $F$ to $m$, is an isomorphism of $m$ with $A$.
But, if $A$ is a proper class (i.e., $F(\alpha) = A$ for no ordinal $\alpha$), I have trouble showing that $F$ is an isomorphism of $\mathrm{On}$ with $A$.  Specifically, I've had trouble showing that $F$ maps onto $A$. (Clearly $F$ is order-preserving, so that $F$ is also an injection; consequently, $F$ is an isomorphism of $\mathrm{On}$ with $F^{\prime\prime}(\mathrm{On})$, so that the solution of this problem rests on showing that $F^{\prime\prime}(mathrm{On}) = A$, i.e., $F$ maps onto $A$.)  
To show that $F$ is a surjection, I've tried proof by transfinite induction on $A$, but I've had trouble showing this "inductive step:"  that if $l$ is a limit element of $A$, and that for each $x \in A$ such that $x < l$ we have $x = F(\alpha)$ for some ordinal $\alpha$, then it follows that $l = F(\beta)$ for some ordinal $\beta$, i.e., $l$ is in $F^{\prime\prime}(\mathrm{On})$.  
Well, I've been thinking: if $l$ is not in $F^{\prime\prime}(\mathrm{On})$, I have been able to show that $l$ is greater than every element of $F^{\prime\prime}(\mathrm{On})$, and that $F^{\prime\prime}(\mathrm{On})$ is a lower section of $A$.  So then $F^{\prime\prime}(\mathrm{On})$ is a proper lower section of the properly well ordered class $A$, hence, $F^{\prime\prime}(\mathrm{On})$ is a set--which clearly should not be, since $\mathrm{On}$ is not a set, and $F^{\prime\prime}(\mathrm{On})$ is isomorphic $\mathrm{On}$.  Now, if I could find a strictly progressing function $g$ on $F^{\prime\prime}(\mathrm{On})$ such that $F^{\prime\prime}(\mathrm{On})$ is superinductive under $g$, then by a theorem, $F^{\prime\prime}(\mathrm{On})$ cannot be a set, so we'd have a desired contradiction.  BUT...it's not clear to me that $F^{\prime\prime}(\mathrm{On})$ is closed under chain unions. (Recall that Ax. Sub. is off-limits.)  So, I'm fairly frustrated.
If you have any experience or thoughts on this, I would be very grateful. (Sorry if my description seems long-winded...) 
 A: I would tend to take an object $*$ not an element of $A$, and define a function $h : \mathcal{P} ( A \cup \{ * \} ) \to A \cup \{ * \}$ as follows:
$$h ( X ) = \begin{cases}
\min ( A \setminus X ), &\text{if $X \subsetneq A$}\\
*, &\text{otherwise}
\end{cases}$$
(so $h(X) = *$ if either $* \in X$ or $X = A$).
Now by Theorem 5.8 there is a (unique) function $F : \mathrm{On} \to X \cup \{ * \}$ such that  $$F(\alpha) = h ( F^{\prime\prime}(\alpha) )$$ for all ordinals $\alpha$.
As you have essentially noted, if $A$ is a set, then there must be an $\alpha \in \mathrm{On}$ such that $F ( \alpha ) = *$.  Taking $\alpha$ to be the least such ordinal, we thereby get an order isorphism between $\alpha$ and $A$.
To go to the proper class version, let us just demonstrate that $F$ maps onto $A$.  To do this we will use the fact that $A$ is properly well-ordered.  So let $x \in A$, and consider $A_{<x} = \{ y \in A : y < x \}$.  Since $A$ is properly well-ordered, it follows that $A_{<x}$ is a set, and is (properly) well-ordered by the restriction of the original ordering on $A$.  
Defining $h_{<x}$ analogously as above (replacing $A$ with $A_{<x}$ everywhere) we can show that $h_{<x} ( X ) = h ( X )$ for each $X \subsetneq A_{<x}$.  By Theorem 5.8 there is a (unique) function $F_{<x} : \mathrm{On} \to A_{<x} \cup \{ * \}$ such that $$F_{<x} ( \alpha ) = h_{<x} ( F_{<x}^{\prime\prime} ( \alpha ) )$$ for each $\alpha \in \mathrm{On}$.  Since $A_{<x}$ is a set, by our work on set well-orderings there is a least $\alpha \in \mathrm{On}$ such that $F_{<x} ( \alpha ) = *$.  Note that this can only happen if $F_{<x}^{\prime\prime} ( \alpha ) = A_{<x}$.  
Now by uniqueness it follows that $F(\beta) = F_{<x}(\beta)$ for each $\beta < \alpha$.  This then implies that $F^{\prime\prime} ( \alpha ) = F_{<x}^{\prime\prime} ( \alpha ) = A_{<x}$, and so $$F ( \alpha ) = h ( A_{<x} ) = \min ( A \setminus A_{<x} ) = x.$$

There are details left to be filled in, but this general outline should work.

