optimaze foreach