Fix bug. Use var instead of int to handle Infinity.