Small modification to avoid issue with floating point rounding errors. Plus adding some comments in the measurement part.