improved CastUtil