Updated the code to check again for the public IP address of an instance instead of only checking once.  The one time the code checks is not sufficient to get a public IP address from a newly created instance.