Many changes to tidy up code and make ime_distance_info also calculate percentile information