Refactored code to separate presentation from analysis