Backport of changes for Linux/PPC64.

Most endian issues and some other problems are gone. Makes the whole thing fly a lot easier.