Moved object instantiation out of the loop