Cleaned up code, memory leak with xmp_data