schedule: refactor next_thread() for better debug printing