Fix disconnection crash
Implement encoder events