refactored device.js to use events api