Added functionality and tests for forEach