extracted binary encoding stuff
totally rubbish, but kind of working