improved byte order handling