CBS has renewed “Elementary” for Season 7.

Though the Rob Doherty-created series hasn’t been performing well in the ratings in the last couple of seasons, the procedural drama remains a major profit generator for the network.

Season 5 of the series averaged 7.4 million viewers and a 1.2 rating among adults 18-49, making it the lowest-rated drama series on CBS during the 2016-2017 TV season.  Despite the decline in ratings, Deadline reported that show has still been a success for CBS Television Studios through its off-network and SVOD deals with WGN America, Hulu Plus, and other broadcast stations that make as much as $3 million total per episode.

In fact, during an investor conference in 2016, CBS Corporation CEO Leslie Moonves used “Elementary” as an example of a program ownership success story, sharing that the show “made approximately $80 million profit for the corporation” in 2015.

That explains why after originally renewing “Elementary” for Season 6 last May with a 13-episode order for midseason, CBS in November ordered eight additional episodes, bringing its Season 6 total from 13 to 21 episodes. According to TV Series Finale, Season 6, which premiered last April, is currently averaging 4.6 million viewers and a 0.6 in adults 18-49 (Live +same day).

“Elementary” stars Jonny Lee Miller as Detective Sherlock Holmes and Lucy Liu as Dr. Joan Watson in a modern-day drama about a crime-solving duo that cracks the NYPD’s most impossible cases. Also starring in the current season are Aidan Quinn as Captain Thomas Gregson), Jon Michael Hill as Detective Marcus Bell), and Desmond Harrington as Michael.

Shortly after the Season 7 renewal was announced, Liu uploaded a promo photo for the show on Instagram. “Looking serious here but really thrilled about @elementaryofficial Season 7! Congrats crew & cast,” the actress captioned the pic.

CBS would not say whether Season 7 would be the series’ final season, but prior to the latest season renewal, Doherty told TVLine that they were doing their best to keep the show on the air. “We want to do everything we can do to keep it from being the last season,” the exec producer said.

“Elementary” airs Mondays at 10 p.m. EDT on CBS.