added smart min/max