Simplify Legendre polynomial code