add caching of min and max value