plotting and cpi functional, consider merging with master soon