added assert_cast and minor tweaks