Trend viewer longest period issue fix
Trends optimizations