Improve finding min and max