fixed bugs to get legendre working