Improve unittests. Improve decoder and encoder
Small refactoring