edited calculation of min and max x