predictor code brought over from js