fixed legendre and quadratic character bug