Fixed bug with last term