The first six games of the Bills’ season are a clear reminder that the NFL never makes any sense. After starting out 0–2, Rex Ryan had the hottest seat in the league, and Buffalo’s promising season was unraveling as soon as it started. In those losses to the Ravens and Jets, the Bills defense was a major problem: The defensive line couldn’t pressure the quarterback, the linebackers were consistently a step slow, and the secondary was regularly getting roasted downfield. So when Ryan fired offensive coordinator Greg Roman, it looked like an act of desperation from a coach looking for a fall guy.

Except it worked. In his short time as the new offensive coordinator, Anthony Lynn has reengineered and expanded Buffalo’s ground game. The Bills’ new-look rushing attack has carried the team to consecutive wins over the Cardinals, Patriots, Rams, and 49ers. It’s saved Buffalo’s season. Here’s how.

When Lynn inherited the Bills offense, he faced the bleak reality that the top weapon in the passing game, Sammy Watkins, wasn’t 100 percent healthy. Buffalo’s success on offense last season leaned on a downfield passing attack that Watkins had anchored, but Watkins’s placement on injured reserve made it an unreliable strategy going forward. With one of their main options eliminated, Lynn decided to double down on the Bills’ other offensive strength: running the football.

After averaging 75.5 rush yards over its first two games, Buffalo has averaged 211.8 yards rushing during this four-game win streak. It hasn’t always been pretty, but facing the Bills right now is like entering the ring for a 12-round heavyweight bout — they’re going to punch you in the mouth, punch you again, and keep punching until the final bell rings. Just ask the Niners, who were knocked out on Sunday. The Bills ran the ball 44 times for 312 yards, and the game played out exactly as the Bills’ punishing offense wanted it to. Buffalo held a slim 24–16 lead early in the fourth quarter, but as the 49ers tired on defense, the Bills’ run game ground the Niners into dust, and it quickly devolved into a blowout.

There was a scary moment in the second quarter when lead rusher LeSean McCoy appeared to have badly injured his knee; up to that point, he’d already amassed two touchdowns and 106 yards on the ground. McCoy would return in the second half for more action; by the end of the game, he had racked up 140 yards and three touchdowns on 19 carries. His three touchdowns against San Francisco matched his season rushing total from all of last year. He became the first Bills back to rush for three scores in a game since Willis McGahee scored four back in 2004. Fellow running back Mike Gillislee chipped in for 60 yards on six carries, Tyrod Taylor added 68 yards on the ground, and even backup quarterback EJ Manuel got in on the action, carrying the ball three times for 11 yards.

Players like Shady and Taylor are natural rushing talents, but both have benefited from Lynn’s adjusted scheme. Buffalo’s attack presents defenses with a wide variety of styles, formations, and looks to prepare for. Lynn reached into his bag of tricks and pulled out a little bit of everything on Sunday.

In the first quarter, Manuel took the field alongside Taylor, a rare two-quarterback-personnel grouping. On this snap, Manuel ran the read option along with McCoy, and when 49ers outside linebacker Ahmad Brooks cheated toward McCoy, the backup signal-caller kept it himself. He ran for 8 yards and a first down.

Later on that drive, Buffalo put some more exotic looks on tape and went with an unbalanced offensive line in the red zone. The Bills shifted right tackle Jordan Mills over to the left side of the line — in between left tackle Cordy Glenn and left guard Richie Incognito — leaving tight end Charles Clay as the de facto right tackle. Instead of running left toward the “heavy” side of the formation where the defense had tilted to, Taylor ran to his right before pitching it to McCoy. The play left Brooks unblocked by design, but Taylor pitched it before Brooks could arrive, allowing McCoy to cut upfield off of Clay’s block on the linebacker downfield for the score.

In the second quarter, the Bills ran another unbalanced offensive-line look — this time with Glenn shifting over to the right side. But they kept the 49ers on their heels by running toward the heavy side of the formation this time around. Incognito pulled to the right from his left guard spot and knocked outside linebacker Aaron Lynch out of the run lane — what’s known as a kickout block — and McCoy followed fullback Jerome Felton through the hole for a 38-yard gain.

Five plays later, Lynn went to the wildcat. McCoy lined up as the quarterback in yet another unbalanced offensive line. At the snap, center Eric Wood pulled to his left — sealing Lynch — which allowed McCoy to follow Felton through the hole before breaking loose for the score.

One of the things that makes the Bills’ run game so dangerous is the threat that Taylor provides as a runner. Buffalo is one of a few teams (along with the Panthers and Titans) that uses the triple option in its repertoire of runs. Late in the second quarter, Lynn dialed one of those plays up. With Brandon Tate lined up behind him in the backfield, Taylor first faked the handoff to Gillislee, then ran to his right, flanked by Tate. When San Francisco defensive back Keith Reaser cheated to the outside to take away the pitch to Tate, Taylor kept it himself to pick up 10 yards.

Two plays later, Lynn got another receiver involved in the action. At the snap, Robert Woods ran an end around, taking the handoff 6 yards for a first down.

The Bills are a tough matchup for anyone because they put so many different looks on the field. Defenses have to account for inside zone, outside zone, and the Power-O (their bread and butter runs), while also preparing for unbalanced line runs, wildcat, triple option, end arounds, and a random two-quarterback look now and then. By using the entire playbook on their rushing plays, the Bills force their opponent to consider all the different coverages they’ll have to be ready for on a given play. The Bills, in essence, begin tossing jabs before either team even steps into the ring.

“We do so much … in the running game,” McCoy said after the game. “It can be at you, around you, misdirection, option, power, fake; I mean our quarterback can run. We have a lot, so when you prepare for us, you have a lot to prepare for.”

McCoy is still the bell cow. He’s thriving in Lynn’s enterprising attack and has run for 470 yards and five scores in the past four games, compared to 117 yards and one touchdown in two games under Roman. But Buffalo’s ground game relies on a multitude of players in its system: Tight ends have to block on the run, receivers have to run with the football at times, and the fullback gets a steady dose of work lead-blocking. The Bills now rely on total commitment to the run game from every player on their offense. It’s an attitude change that’s turned their season around.