changed MIN/MAX to std:min/max