Exactly! For many drugs it's essentially a funny accident of history that they were originally discovered while attempting to cure something completely unrelated to what is now their primary usage.