Updated context switch algorithm to reflect a program ending.