changed the max's to min's in min function'
'