Fish like that often suffer from a reverse effect - a sudden vast improvement in water quality and care stresses them out a lot. Living organisms have an amazing adaptive capacities but these take time to develop. This fish has learned and developed to survive in a horribly little tank and more than likely in poison-laced water. That takes rebuilding of the fish's entire organism to cope with these specific threats, including internal organs, brain, reflexes, hormones, etc. etc. etc.
Take it out of the bad and put it in the good and fish may not handle it. SDS sudden death syndrome is not too uncommon in this situation either it appears to me from a scarce experience and reading around.
Anyway, cudos for you and have patience. For all we know the fish may rebound or might have been already on the brick of death when you took it in and nothing can help it. Time's on your side. IME, if it survives past 3-6 months, SDS becomes rather unlikely, it'd be mostly out of the woods.