I got to the same answer after a lot of work and trial and error. Not really sure how your differentiation works but I'll attach a copy of my workings so you can have a look. Apologies for crappy horizontal photo and text format but on a phone I'm not good at using.
Your work looks good. I think that's the right way. My dfferentiation was most likely not correct since r is a variable and not constant. But I assumed it as a constant. Thanks!