Added do_trend function. Added control on input parameters