I know whats wrong, but not why
if that statement is true then there are only 2 reasons(that i can think of)
a) you misunderstand something that you know is happenning
b) something is happenning that you dont know about.
try taking the particular code that doesnt work and running/testing it in a seperate environment outside the rest of your program.