SANTA CLARA, Calif. -- After a pair of small trades in both directions, the San Francisco 49ers departed the first day of the NFL draft with a decidedly different-looking defense than the one that was among the worst in the league in 2016.

To help start Thursday night's fireworks, the Niners moved down one spot, from No. 2 to No. 3, in a trade with the Chicago Bears before using the third pick on Stanford defensive lineman Solomon Thomas. Then, after watching Alabama linebacker Reuben Foster's lengthy slide down the draft board, the Niners jumped three spots back into the first round to take him at No. 31 after a deal with the Seattle Seahawks.

When the smoke cleared, the Niners had in tow the players they ranked Nos. 2 and 3 on their overall board, just behind Texas A&M defensive end Myles Garrett. General manager John Lynch even acknowledged that if the Bears had taken Thomas with the second pick, the Niners would have strongly considered taking Foster with the third pick.

"I can tell you right off the bat that what we had on the board was just under 200 players, and in terms of how we rated them, we got two of our top three players," Lynch said. "We were able to do that, and we're thrilled. We're ecstatic. We think these guys have a lot of traits of what we want to be about as a football organization."

With his first pick running an NFL draft, Lynch selected Thomas, calling the name of a player from his nearby alma mater and, believe it or not, a former classmate.

But first, Lynch and the Niners picked up some extra draft capital in a trade that came while they were on the clock at No. 2. San Francisco dealt that pick to the Bears for the No. 3 pick and the Bears' third-round (No. 67 overall) and fourth-round picks (No. 111) this season and the Bears' third-round pick in 2018. The Bears selected North Carolina quarterback Mitchell Trubisky with the pick acquired from the 49ers.

According to Lynch, the trade was the product of work done by Paraag Marathe, the Niners' chief strategy officer and executive vice president of football operations. Lynch said the Niners had multiple teams bidding on the pick, which helped increase the return.

"I always find it really cool that [former coach] Bill Walsh charged Paraag at one point with coming up with our own trade chart, and so he did that, and we used it very well today," Lynch said.

As for Thomas, Lynch made the rounds at multiple pro days around the country during the pre-draft process, but his absence was noticeable when Stanford held its showcase for players, not only because Lynch played there but also because the Palo Alto campus is 22 miles up the road from Levi's Stadium.

When Lynch was then asked whether Thomas and running back Christian McCaffrey would pay a visit to the Niners' facility before the draft, Lynch demurred, noting that the Niners already knew those players "pretty well." Thomas said Thursday night that he met with Niners defensive line coach Jeff Zgonina at the scouting combine but that otherwise contact with the Niners was limited over the past few months.

Solomon Thomas, the No. 3 overall pick, was ranked No. 2 on the 49ers' overall draft board, according to general manager John Lynch. Bill Streicher/USA TODAY Sports

As it turns out, the relationship between Lynch and Thomas began long before the pre-draft process. When Lynch returned to Palo Alto to finish his degree a few years ago, he shared a management science and engineering class with Thomas, who was in his freshman year.

Thomas, who said he was starstruck when he realized he had a class with Lynch, worked on a project with his now-boss evaluating whether the Washington Redskins should change their nickname. He and Lynch have kept in touch since, making Lynch's evaluation of Thomas relatively easy leading up to the Niners' pick.

With Thomas' draft stock rising late last season, he even touched base with Lynch for advice.

"During the pre-draft process, before we played North Carolina, he told me, 'Don't worry about the external stuff going on. Worry about yourself and your team. The best thing you can do is go have the best bowl game possible and just go show them you're unstoppable and unblockable,'" Thomas said. "I took that advice seriously, and I went to go do it."

Thomas went on to have his best game, posting seven tackles and two sacks and forcing the game-winning sack against Trubisky and Carolina in the Sun Bowl.

Apparently, that knowledge, combined with Thomas' college production and the Niners' need to simultaneously bolster the pass rush and run defense, was enough to make Thomas the second player on the team's board behind Garrett.

For the Niners, Thomas will be expected to instantly improve a defense that finished last in the NFL in 2016 in yards allowed and rushing yards allowed and was fifth-worst in the NFL in pressures generated per dropback.

Upon adding Thomas, the Niners have now used their top pick in each of the past three drafts on the defensive line, having selected Arik Armstead in 2015 and DeForest Buckner in 2016. Zgonina told Thomas at the combine he would envision him working at left defensive end in coordinator Robert Saleh's 4-3 defensive scheme, with the versatility to move inside to defensive tackle in passing situations.

"I talked about that with the defensive line coach at the combine," Thomas said. "Kind of lining up in the end position and stuff so I can move down to that three-tech and be able to rush with DeForest or Arik in there. So, you know, that's really what we talked about, and I'm excited to figure out and learn more about the system."

Foster, meanwhile, had a much longer wait to hear his name called. Although he was once projected as a potential top-five pick, his stock fell because of a shoulder injury, a positive drug test for a diluted urine sample and an argument with a hospital worker at February's scouting combine that resulted in his ejection. Foster also has been recovering from a right shoulder injury, which he said is now 90 percent healed and should be back at full strength in time for training camp.

To feel comfortable taking Foster, the Niners put in a lot of work. He met with them at the combine and was the team's first pre-draft visitor in March. Coach Kyle Shanahan and Lynch both also spent time talking to Foster on the phone and via FaceTime. When things got more serious, they sent vice president of football affairs Keena Turner and team chaplain Earl Smith to Tuscaloosa to meet with Foster for two days.

"We were exhaustive in getting to know the kid," Lynch said. "It felt genuine. That's something we loved about Reuben is that he's really genuine, he's got a smile that lights up a room, and the way he plays football is special."

As Foster's slide continued, the Niners began calling just about every team in the league to move up to get him, according to Lynch. He said the calls began in the teens and didn't stop until the Niners surrendered the fourth-round pick they acquired from the Bears to move the three spots necessary to land Foster.

For his part, Foster was excited to land in San Francisco even after his surprising fall.

"I'm trying to be the great, the next Patrick Willis, the next great linebacker in their history," Foster said. "I was very surprised. I thought I wasn't going to make it. I thought I wasn't going to make it, but I'm just happy that they just believed in me and just trusted in me and to pick me and just give me a chance."

The Niners expect Foster to come in and compete for a starting linebacker job right away. He's likely to get a look at inside linebacker, though Shanahan says he believes some combination of Foster and NaVorro Bowman will handle the inside and weak side linebacker spots in tandem. Competition throughout the spring and summer will determine who lines up where.