bug fix + unit tests for encode/decode hex