refactor and added chart.js