Reimagined the foreach function using lambda functions. It's pretty cool.