improve min and max