BUG: when xmax = 10, innermost while loop ends before last iteration of x2 <= xmax.
Action: nothing can be done except avoid xmax = 10 values or any other varmax for that matter.