Plotting script and some fixes