WIP: reorganizing chart code