refactor some of the calculations in the APMonitor notebook