moved all `sched_exit()` calls to one final statement