core: refactor sched_run

`sched_run()` was cluttered. Many individual changes were done without a proper refactoring.

Rebased on #1836.
the typo is in "done, not sched", no in "return 0;" btw.