Improve BEncodeDecoder and adapt unit tests