Break materialize function apart and put trendstore modifying logic in own functions.