Refactor analyze_files