your rewrite version gave me an error saying hash table already exists upon executing your code the second time.
you probably didnt check the hfree after the sockclose, i tested it with many link and worked
by the way, you're not the only one who saw that this script its probably not the original one... i remember that i saw something like this on the request forum