I couldn't sleep for awhile and I was taking pills and trying anything you name it....but finally, I can sleep again

I just reduced my stress level.....relationship that was causing me so my tension has gone away from me and I don't go to the places that cause me stress.....and I do meditate at night and I exercise more.....then I can sleep well