Fix foreach loop to work only with keys