refactor canvas.js