BF: better events polyfill and added new foreach polyfill