cleaned up spawning logic for readability