Prepare module for publication

* Use spawn instead of exec
* fixup emitted events
* refactorings
* cleanup