Refactoring charts.py