finished with rescale, so that when xmin and xmax is not properly set, it can be fixed automatically