Fixed for_each bugs