Cleaned up foreach loop