Seems to me the maxval and minval are filled in setup and their values don't change for the duration of the program. If this is the case, then store them in EEPROM. There is 1KB of EEPROM on arduino, which is exactly how much you need to store maxval and minval both.