The story of Kesha Rose Sebert can be told with two songs from her first demo tape. They were written in her teens after she moved to Nashville with her mother, country songwriter Pebe Sebert. The first, Billboard described as a “gobsmackingly awful trip-hop track... at one point toward the end, Ke$ha runs out of lyrics and starts rapping, for a full minute or so: ‘I’m a white girl/From the ’Ville/Nashville, bitch.’” The other? “A gorgeously sung, self-penned country ballad that hints at what could've been had Ke$ha pursued a different path.” Former producer Lukasz “Dr. Luke” Gottwald, with whom Kesha is embroiled in a series of lawsuits about his alleged sexual and emotional abuse, preferred the high-octane rapping track. This choice would define Sebert’s sound, image, and career as the flagship artist for his label Kemosabe—a career she’s grappled with ever since. The fact that Rainbow exists at all is a feat unto itself.

In the years since her 2010 debut Animal—which housed the massive No. 1 club-pop hit “Tik Tok”—much has changed in the greater music world. Virtually every pop star of the early ’10s has written off the gonzo sound just as Kesha has. Rihanna released an album proclaiming herself “anti”-it all. Lady Gaga shed glamour and gimmicks for a guitar-based album with her middle name instead of her noble sobriquet. Miley Cyrus quit twerking in a butter costume, made lite-rock, and called it a spiritual awakening.

Kesha has more claim to this career trajectory than some—her Nashville roots are established, and any new music by her would basically have to depart from Gottwald’s sound. For the past few years, Kesha was legally barred from releasing music, a clause she bypassed with a series of unofficial-ish concerts. Yes, it’s remarkable that Rainbow exists, but the fact that it’s pretty good is even more remarkable. The album could easily have been designed to fail, like a vengeful Sony Music fulfilling the letter of their responsibilities by foisting upon Sebert C-list producers. Just as perilously, it could have been a stolid album, Kesha as the prodigal pop star, apologizing for her past hits via self-consciously “authentic” tracks that snuff her personality.

There is still some of that; Rainbow is inevitably heavy with subtext and a need to prove something, especially on “Praying.” Kesha commits emotionally and vocally (one high note spawned actual reaction videos); the lyrics—righteous warnings that tiptoe up to the line of litigation (“We both know the truth I could tell”)—execute their intention precisely. But it’s still a pro forma piano ballad, produced by collaborator Ryan Lewis (of “Macklemore &” fame) with a plodding track and sloppy comping of Kesha’s vocals, particularly on the verses. It works more as a statement than a song. The title track, a collaboration with Ben Folds that blooms into a string arrangement, is an improvement, but still sedate.

Thankfully, the rest of Rainbow lets Kesha be her usual OTT self. Studio banter is left in; on some tracks she breaks down into laughter like her ad-libbed, “I like your beard.” Since Warrior, Kesha had fought for rock tracks, with limited success; Iggy Pop made that album, but a very toned-down version. Rainbow substitutes Eagles of Death Metal. The exuberant “Let ’Em Talk” is like closing-credits music for her own story, and “Boogie Feet,” despite the inauspicious title, is surprisingly beefy, culminating in a glam call-and-response as fun as anything she’s done. Kesha tears through country as she does rock. “Hunt You Down” is a blatant June Carter homage—it name-drops “I Walk the Line” halfway through, for those who hadn't gotten it before—and its goony stalker glee makes for something like a rockabilly version of her song “Stephen.”

If there’s a reason that Rainbow doesn’t seem cohesive or an album that autonomously belongs to Kesha, it’s more a byproduct of her situation. Kesha still owes two more albums to the label she fought to leave, and here she grapples with her commercial whims. While “Praying” is hanging on at adult pop radio, very little is positioned to follow it. One promising direction is, of all things, twee: “Bastards,” “Godzilla,” and “Spaceship” land somewhere between Kacey Musgraves and freak-folk, lightweight campfire songs that make monster rampages and profanity sound wholesome and weirdly touching. Sebert could also return to her roots, as on “Old Flames (Can’t Hold a Candle to You),” Pebe Sebert’s biggest hit, popularized by Dolly Parton. Parton, always known for supporting her acolytes, guests on this fuller arrangement, and there’s an appealing sense of a legacy passed on.

Perhaps the most promising direction on Rainbow is “Woman,” featuring the Dap-Kings Horns. The mere existence of this song is something of a conceptual coup. Kesha has replaced the producer who once suggested that “A-list songwriters and producers are reluctant to give Kesha their songs because of her weight” with the backing band beloved by Mark Ronson, not to mention the late Amy Winehouse and Sharon Jones. Like most artists would, Kesha inhabits this lineage a bit tentatively, and “don’t touch my weave” is a lyric perhaps best delivered by someone other than Kesha Sebert. But she’s having fun: laughing through the song, proclaiming herself a “motherfucking woman” on the colossal hook. Her early records, of course, were meant to be fun; here, one can unequivocally say Kesha has joined in.