fixes and additions to deal with byte order