modified the computation of max depth to be much more cleaner
modified all casting to more cleaner casting of valuetype
small fix
fixed some typdef bugs/