Better error handling, set endian correctly