refactored the analysis part