Added this and the suggestion of @TheDigitalOrchard above for $max