min function fixed