move object instantiation out of te foreachs