refactor chart.py into more manageable code