final version of the analysis script