Fix possible infinite loop in computeprofiles
Fix small bug in Invert