use gnu99 for foreach
added foreach