move spawn function around