Make event mapping more functional and testable by moving it out of the device class, and add tests for it.