canvas.js refactoring