Spawn refactor

Can you review, @geertj?