improve trend calculation script.