Several changes

* Bugfix encoding
* Improve tests