Merge "Refactor the trellis optimization process" into nextgenv2