Object creation outside while loop