events.js improved