adjusted plotting, added analysis function