Refactoring main plotting script