this is the part that is giving you the error.
($max-$old)
in this case, $max-$old=0 which is bad.
so, before you get to this point, check that max is set, that old is set (just good practice), and that max-old does not = 0. that should fix ya right up