select min and max element here. why do you store temporary values?