Fix undefined $max error