removed extraneous dependencies
fixed function scope for outer forEach