Refactoring of all code above classes to simplify analysis and plotting