updated to use next_run instead of num - 1