start of function to calculate next run