Refactor to clean up the main GenerateChart script