Implementing cloning of the middleware chain (Needed because the
priority queue will be mutated during processing).