Merge "Refactor trellis optimization process" into nextgenv2