Improved code performance (Math.Pow(x, 2) replaced with x * x and similar cases).
Code formatted.