Refactoring of the plotting script.