> if(overlap=1)
What does this do?

> overlap=0;
And this?

It seems to me that the assignment in the if statement makes sure all this code happens every time.