Fixing endianess detection and memory leaks