Updated to include functions in main analysis script