solved error with functions for foreach
pop results to prevent stack pollution