Enhance the optimization to work on all rightmost insert patterns