Refactoring

- Abstract control flow out of the library
- Use `util.inherits` to inherit the emitter class
- Remove `createListener` wrapper