Rewritten the mess that was the binary conversion routine