The cast checks need to be done as a separate pass.

This is due to invalid cast exceptions getting thrown at odd times.
Little bit nasty but a lot safer.