Add _check_unit and _check_can_cast to reduce code duplication
Resolve bug from rebase