used Math.min() instead of min()