changed quadratic logic