Rfc6810 bis

pull request for reviewing code
The casts could be unnecessary here