could be these string to number comparisons causing it