1. Moved object initialization outside the while loop
2. aligned code in the models