move out table building logic to external function
move out chart building logic to external function