i thought gym will help me

i decided to go to the gym for almost six months, to make myself tired at night and sleep. i proud of myself.

however, i faced 2 different new situation which is;

  1. I felt hornier and relapse before sleep; or

  2. I suddenly woke up in the middle of the night and relapse. (can't control myself and relapsed)

what the fuck is wrong with me? i thought gym will help me to avoid relapsing ( yes it actually helped, in terms of physical and mental state) but i don't want it to become another factor of me to relapse.

opinion/omment/adivce are highly appreciated. thank you