refactored spawn