Stricter casting.

Replace reinterpret_casts in some places we are doing downcasts.