Stock turned from halal to non-compliant and back to compliant

Assalamu Alaikum. Mufti I have read your rulings on similar scenarios but not exactly the same as mine so I would really be grateful if you could please advise on this. I basically some shares of a company throughout 2021, 22 and once in Jun 2023. Few months after my last purchase, I noticed this company’s stock started showing up as not permitted on one of the Islamic Apps. Just to clarify when I bought this stock, this was always halal to the best of my memory.

So I waited because I read somewhere that some stocks can rebound back into halal. Now since it has been 4 months since this stock became haram, I want to sell it off but here is where it gets interesting. I don’t have much knowledge of Islamic Finance but one thing that this app looks at is ‘Interest Bearing Debt’ and anything higher than 30% is not permissible. Formula for calculating this Debt is ‘Total Debt / Market Cap’. But this company has had a rebound since December and its Market Cap has considerably risen so if I were to calculate today, it is halal and this figure is around 24 percent! It still appears as non-compliant since the App only calculates Market Cap when the company reports its earnings which I think is due next month.

Since the app doesn’t update the formula regularly, so I did some quick calculations and I think it is likely the stock may have been non-compliant since beginning of 23 and only became compliant again in December 23 when Market Cap rose considerably. I still want to sell it because I find this ‘grey area’ as it is fully possible that their Market Cap may dip again in the future making it haraam but I am not sure what to do with the amount I get back from selling it.

Generally from what I have read is that if stock goes into non-compliant category, you sell it and if the selling stock price is higher than what you bought it for, you just keep the amount up till it was halal and give rest to charity. However the stock is halal now and its share price is much higher than when it was haram. In fact the reason it was haram was because market cap and stock price dipped leading to much higher Interest Bearing Debt. Mufti could you advise what do I do with the money I get back when I sell all shares I have of this company now?