fixed spawning code