Particle Collision Event Procedure

Hi all. First of all, I am fairly new to MEL. Now that that is out of the way, let me say that I have been working with some simple scripts that I have written in order to work with particles. What I want to happen is for a particle system to leave geometry behind after a particle has collided with an object. Imagine a bird laying an egg after it hist a window. I have succeeded in creating a Particle Collision Procedure that creates a pSphere when the particles collide, so not very difficult. But what I want is for those sphere to be placed where the particle collides. The procedure works, in some odd and wrong way. Basically, spheres are placed in the positions, but there is some erronious looping that occurs . . .like 10400 extra loops, but maya doesn't crash, it just computes and continues, but it takes a long time. Some of the lat part of the code I have used successfully as a runtime expression to connnect geometry to particles. I thought I would try to use it in this manner. Any help would be appreciated as I am a little lost at this point. I have a simple working model that would work for simple presentation purposes, but this is supposed to work in a model of a downtown area of a city. Thanks!

CODE
//----------------------------------------------------------------
//--------Initiate Global Procedure-------------------------------
//----------------------------------------------------------------

global proc pTest014(string $particleName, int $particleId, string $objectName)
{

//----------------------------------------------------------------
//--------Create Seeds--------------------------------------------
//----------------------------------------------------------------

    print ("Collided with" + $objectName + "\n" + "\n");
    print ($particleId + "\n");
    polySphere;

//----------------------------------------------------------------
//--------Place $particleID in array------------------------------
//----------------------------------------------------------------

    int $seedsInScene[];

    for ($i=0;$i<100;$i++)
        {

        $seedsInScene[$i] = $particleId;
        print ($seedsInScene);

//----------------------------------------------------------------    
//--------Go Through $seedsInScene[] array with $seedObject-------
//----------------------------------------------------------------

        int $seedObject;

        for ( $seedObject in $seedsInScene)
            {

//----------------------------------------------------------------
//For each $particleId collision stored in $seedsInScene, place---
//psphere at the position of the particle that collided-----------
//----------------------------------------------------------------

    $pos = getParticleAttr -at position ($particleName + ".pt[" + $seedObject + "]");

                    setAttr ("pSphere"+$seedObject+".tx") $pos[0];
                    setAttr ("pSphere"+$seedObject+".ty") $pos[1];
                    setAttr ("pSphere"+$seedObject+".tz") $pos[2];

            }

        }    

};

Have you tried using the built in "particle collision event" wizard? Basic steps are:
1.create an emitter and particle
2.create a collision seface (sphere)
3.Select the particle and sphere and choose "make collide"
4.Select the partilce and invoke the "particle collision event" wizard from the menu
5.Set options and create event that happens on collision, such as a new partcile is born, the old particle dies...

What I want to happen will need to keep the particles alive. The particles are to collide with a built environment of a city. I have already set the particles to collide with all of those objects. I want the particles to create geometry on collision, and I want that geometry to be placed where the particles collide with the buildings. So I have been trying to pass the $particleId to an array that holds the collided particles. Then I have a for-in loop that goes through the array and replaces the position of the spheres with that of the collided particles. But I feel I am horribly missing something. I feel that the Particle Collision Event Procedure is the way to go.

sorry, solved the problem . . . made the code cleaner . . . not all problems gone, but at least this is much faster!

CODE
//----------------------------------------------------------------
//--------Initiate Global Procedure-------------------------------
//----------------------------------------------------------------

global proc killParticlesTest015(string $particleName, int $particleId, string $objectName)
{

//----------------------------------------------------------------
//--------Create Seeds--------------------------------------------
//----------------------------------------------------------------

    print ("Collided with" + $objectName + "\n" + "\n");
    print ($particleId + "\n");

    polySphere -n ("pSphere"+$particleId);

    $pos = getParticleAttr -at position ($particleName + ".pt[" + $particleId + "]");

                    setAttr ("pSphere"+$particleId+".tx") $pos[0];
                    setAttr ("pSphere"+$particleId+".ty") $pos[1];
                    setAttr ("pSphere"+$particleId+".tz") $pos[2];
}