Modified closedloopdata_analysis.R