After taking sleeping pills for 21 years I'm beginning to feel it's hopeless and I have to accept myself this way

I have no problem falling asleep since I have a whole collection of pills: tylenol pm, melatonin, sleep gels, benedryl. But at 4am? Or 5am? That's when the racing thoughts start, spinning ...spinning... out of control. Feeling depressed about it I reach for a sleeping pill. It always works. But I hate this. My doctor said it's "quite common." He isn't alarmed.