changed to use Math.max() as discussed