this function is huge.  i'd define `remote_prediction()` and `local_prediction()` (or something like that) and make `predict()` call them.