Get rid of the casts by introducing an extra function.