replaced the vars in the foreach loops