refactor chart into functions