refactoring plotting and analysis