changed: outsourced cast code