implemented internal-only ``cast`` function