moved code up to for loop, and formatted the rest as markdown (not excuted) code.  Also centered figures because this is prettier