Modified queue algorithm.