Fix some issues with Stack middleware merging.