Refactored analysis.py