Improve type checking code

The name zval_fits_type needs a review; unsure what else to name it.