debugged the function with respect to foreach()  ...it turns out that one cannot use return() at the end of a function when iterating with foreach(), but rather has to more "crudely" return the object in question by simply calling it at the end of the function.