added plotting and writing out results file