Fix templated cast