Simplified implementation of model.when