better handling of .cast()