core: refactor sched_run

`sched_run()` was cluttered, changed changed without refactoring a lot.

Rebased on #1836.
Very helpful, thanks! The current debug message really sucks.