fix max/min functions