FIXED error when using Math.min not Math.max