Fixed small bug in gradient and potential terms.