made apply_model more general