Some more fixes in the prediction routine. This is a work in progress.