Fix endianness and cleanup