Roman legions were designed as maniples and cohorts, which made them more flexiable, also the Roman used the 3 line formation, allowing them to hold an enemy back even if they are overstretched since each line takes the charge and the next line stops it, where a phalanx formation used by everybody else would stick most of their infantry in one single line, making it very vulnerable to being outflanked. Romans could use their maniples and triple line to easily deal with a flank attack or a rear attack by turning maniples on the back line around with ease, while a phalanx would need a reserve phalanx to counter any breakthrough through their line or being outflanked and attacked from the rear, this is why Romans were so good at retreating, they had more counter depth(Counter attack deepness), while the phalanx had more depth. Both phalanx and roman manifolds and cohorts would rotate exhausted men at the front line with thr man behind him and go to the back of his column like a caterpillar,although the Macedonian phalanginist probably did not do this.