Bad implementation using foreach.