fix crash in spawning algorithm