Fix scheduler bugs