refactor trends.py