create min function (untested)