Tidied things; wrote the plot function.