Refactored the saving of plots