updated to use the stock min/max functions