working model, cpi runs but may be incorrect, plotting functions are pretty