transfered to using min and max