improve casting
add some tests