refactored and restructiored chart generation