Added #1413, fix math.max from my previous commit