implemented reduceterm