Refactor modelTo

Refactored lookup code into `lookupModelTo`; make sure params.as is not overwritten.
When compared with L439-L447, I see a possibly unintentional change: When `params.model` is neither a string nor a function, then the value is silently ignored. Before this change, the value was assigned to `modelTo`, which probably caused a runtime error later.

While you are at fixing that, it may be worth ignoring an empty string value of `params.model` too.