Yes I got your point and you can decrease the amount of looping and get your problem solved.

In that thread I have commented the complete source code and so that should help you more.

http://www.go4expert.com/showthread.php?p=3161