If you want us to help you understand why your program does what it does, you have to show us the code for the program -- or, if it is lengthly, a stripped-down version that illustrates your problem.
Huh... The danged Troll Proximity Indicator is acting funny again.