Move encoding to js

* #56 
* #57