handle endian properly, and a few more cosmetic changes