code and plot cleanup