factoring out typecasts from model code